package edu.vt.ece.rt.benchmark.skiplist;


import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.Random;

import edu.vt.ece.rt.benchmark.counter.Counter;


public class Benchmark extends edu.vt.ece.rt.benchmark.Benchmark {

	private Random random = new Random(hashCode());
	
	
	
	@Override
	protected void createLocalObjects() {
		SkipList.head = new SkipList("head", 0, 33);
		SkipList level = new SkipList("levels", 1, 1); // special object where val stores level
		InputStream file1;
		try {
			file1 = new FileInputStream("random");
	
		InputStream buffer1 = new BufferedInputStream(file1);
		ObjectInput input1 = new ObjectInputStream(buffer1);

    	ArrayList<Integer> arr1 = (ArrayList<Integer>)input1.readObject();

		for (int i = 0; i < localObjectsCount; i++)
			SkipList.InsertInit(i, arr1);
		
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	
	@Override
	protected Object randomId() {
		return null;
	}
	
	
	@Override
	protected int getOperandsCount() {
		return 0;
	}

	@Override
	protected void readOperation(Object... ids) {
		int val = random.nextInt(localObjectsCount);
		if (SkipList.contains(val, null)) {
//			System.out.println("Contains "+val);
		} else {
//			System.out.println("Cannot find "+val);
		}
	}

	@Override
	protected void writeOperation(Object... ids) {
//		System.out.println("Nesting is "+nesting);
		SkipList.write(localObjectsCount, nesting);
	}

	@Override
	protected void checkSanity() {
	}


	@Override
	protected String getLabel() {
		return "skiplist-qr";
	}
	

	
}